package com.mo2323.merchant.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.mo2323.common.VO;
import com.mo2323.common.VOList;
import com.mo2323.common.util.AjaxObject;
import com.mo2323.service.merchant.IFieldReserveService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author xjw
 * @date 2019/1/24 - 16:34
 */
@Controller
@RequestMapping("/fr")
public class FieldReserveController extends BaseController {

    @Reference
    private IFieldReserveService fieldReserveService;

    @RequestMapping(value = "/openLight", method ={RequestMethod.POST, RequestMethod.GET} )
    @ResponseBody
    public AjaxObject openLight(@RequestParam String slipNumber) {
        try{
            Boolean flag = fieldReserveService.fieldReserveOpenLight(slipNumber);
            return AjaxObject.ok().put("data", flag);
        } catch (Exception e){
            logger.error("openLight Exception：", e);
            return AjaxObject.error("openLight Exception：" + e.getMessage());
        }
    }

    @RequestMapping(value = "/list", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public AjaxObject getFieldReserveList(@RequestParam int vid, @RequestParam String date) {
        try {
            List<VO> list = fieldReserveService.getFieldReserveList(vid, date);
            return AjaxObject.ok().put("data", VOList.I(list).getData(true));
        } catch (Exception e) {
            logger.error("getFieldReserveList Exception：", e);
            return AjaxObject.error("getFieldReserveList Exception：" + e.getMessage());
        }
    }

}
